package allen.util;

/**
 * Provides some util method for array.
 * */
public class ArrayUtil {

	private static int countBoolArray(boolean[] boolArray, boolean value) {
		int result = 0;
		if (boolArray != null) {
			for (int i = 0; i < boolArray.length; i++) {
				if (boolArray[i] == value)
					result++;
			}
		}
		return result;
	}

	private static int countBoolArray(boolean[][] boolArray, boolean value) {
		int result = 0;

		if (boolArray != null) {
			for (int i = 0; i < boolArray.length; i++) {
				boolean[] tem = boolArray[i];
				result += countBoolArray(tem, value);
			}
		}

		return result;
	}

	/**
	 * Compute the number of value true in this array.
	 * */
	public static int countTrueOfArray(boolean[][] boolArray) {
		return countBoolArray(boolArray, true);
	}

	/**
	 * Compute the number of value true in this array.
	 * */
	public static int countTrueOfArray(boolean[] boolArray) {
		return countBoolArray(boolArray, true);
	}

	/**
	 * Compute the number of value false in this array.
	 * */
	public static int countFalseOfArray(boolean[][] boolArray) {
		return countBoolArray(boolArray, true);
	}

	/**
	 * Compute the number of value false in this array.
	 * */
	public static int countFalseOfArray(boolean[] boolArray) {
		return countBoolArray(boolArray, true);
	}
}
